<?php

namespace app\desktop\controller\components;

use app\desktop\controller\Base;
use app\helper\DictionaryHelper;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;

class DictionarySelect extends Base
{
    public bool $isApiAuth = false;

    /**
     * 得到字典
     * @return Response
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getDictionary()
    {
        $type = $this->request->get('type', '');
        if($type === ''){
            return $this->getErrorResponse('字典类型不能为空');
        }

        $dictionaryHelper = new DictionaryHelper();
        $dictionary = $dictionaryHelper->getList($type);

        return $this->getSuccessResponse('获取成功', $dictionary);
    }
}